package com.tudou.api.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class VideoUrl {
	public String itemid, debug, sys_code, business_code;
	public ItemUrl[] itemUrls;
	
	public static VideoUrl parseVideoUrl(String data){
		VideoUrl urlData = new VideoUrl();
		try {
			JSONObject jobj = new JSONObject(data);
			urlData.itemid = jobj.getString("itemid");
			urlData.debug = jobj.getString("debug");
			urlData.sys_code = jobj.getString("sys_code");
			urlData.business_code = jobj.getString("business_code");
			JSONArray urlsObj = jobj.getJSONArray("itemUrls");
			urlData.itemUrls = new ItemUrl[urlsObj.length()];
			for(int i = 0; i < urlsObj.length(); i++){
				urlData.itemUrls[i] = new ItemUrl();
				urlData.itemUrls[i].fid = ((JSONObject)urlsObj.get(i)).getString("fid");
				urlData.itemUrls[i].definition = ((JSONObject)urlsObj.get(i)).getString("definition");
				urlData.itemUrls[i].indx = ((JSONObject)urlsObj.get(i)).getString("indx");
				urlData.itemUrls[i].videotype = ((JSONObject)urlsObj.get(i)).getString("videotype");
				urlData.itemUrls[i].url = ((JSONObject)urlsObj.get(i)).getString("url");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return urlData;
	}
}
